var utils = require("../../../utils/util.js");
var app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
Page({
  data: {
    imgUrls: [],
    posterShowView:true,
    videoShowView: false,
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    defaultSize: 'default',
    primarySize: 'default',
    warnSize: 'default',
    disabled: false,
    plain: false,
    loading: false
  },
  onReady:function(res){
    var that = this;
    that.videoContext = wx.createVideoContext('myVideo')

  },
  onLoad: function (options){
    var that = this;
    wx.request({
      url: utils.dominame+'/api/reserve_project_info',
      data: {
        project_id: options.id
      },
      method: "GET",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      complete: function (res) {},
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          var temp = WxParse.wxParse('article', 'html', res.data.data.project_info.detail, that, 5);
          that.setData({
            flag: false,
            article: temp,
            title: '商品详情',
            dominameImg: utils.dominameImg,
            project_name: res.data.data.project_info.project_name,
            imgUrls: res.data.data.project_info.show_pic.split(','),
            add_time: res.data.data.project_info.add_time.split('.')[0],
            video_url: res.data.data.project_info.video_url,
            id: res.data.data.project_info.id
          });
        }else{

        }
      }
    })
  },
  buyNow:function(){
    var that=this;
    wx.navigateTo({
      url: '../hotelSystemSubmitOrder/hotelSystemSubmitOrder?id=' + that.data.id + '&projectName=' + encodeURI(that.data.project_name),
    })
  }, 
  playVideo:function(ops){
    var that = this;
    that.setData({ posterShowView: false, videoShowView: true });
    that.videoContext.play(); 
  },
  onShareAppMessage: function (res) {
    console.log(res)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: this.data.project_name,
      path: '/pages/hotelSystem/hotelSystem/hotelSystem',
      imageUrl: utils.dominameImg + this.data.imgUrls[0],
      success: function (res) {
        // 转发成功
        wx.showToast({
          title: '分享成功',
          icon: 'none'
        });
      },
      fail: function (res) {
        // 转发失败
        wx.showToast({
          title: '分享失败',
          icon: 'none'
        });
      }
    }
  }
})